<?php
	if(!defined('BASEPATH'))
		exit('No direct script access allowed');

	class m_TimewarnerAPI extends CI_Model
	{
		function __construct()
    	{
    	    // Call the Model constructor
    	    parent::__construct();
    	}
		
		function get_user_id($userid)
    	{
			$this->load->database();
			$this->db->select('userID')->from('TimeWarnerCableBills')->where('userID', $userid);
			$query = $this->db->get();
			return $query;
    	}
		
    	function get_bills($userid)
    	{
			$this->load->database();
			
			$this->db->select('*')->from('TimeWarnerCableBills')->where('userID', $userid);
		
			$query = $this->db->get();
			return $query;
    	}
		
		function paybill($invoiceID)
		{
			$this->load->database();
			$this->db->update('TimeWarnerCableBills', array('State' => 'Paid'), "invoiceNumber = " . $invoiceID);
		}
		
		function validate_user($userid)
		{
			//Validate user			
			$this->load->database();
			$query = $this->db->get_where('TimeWarnerCableBills', array('userID' => $userid)); //userID DOES exist
			$query_result_size = sizeof($query->result());
			
			if($query_result_size)
			{
				//userID DOES exist
				return 0;
			}
			else
			{
				//userID does NOT exist
				return -1;
			}
		}
	}
?>
